import 'package:basic_common/app_theme.dart';
import 'package:basic_common/bottom_sheet_tool.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/input_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'personal_controller.dart';

class PersonalPage extends GetView<PersonalController> {
  const PersonalPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: backAppbar(title: "个人资料", actions: [
        GestureDetector(
          onTap: () {
            controller.updateDrInfo();
          },
          child: Container(
            alignment: Alignment.centerRight,
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Text(
              "修改",
              textAlign: TextAlign.center,
              style: TextStyle(
                  color: AppTheme.primyColor, fontSize: ScreenHelper.sp(16)),
            ),
          ),
        )
      ]),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
        color: Colors.white,
        child: SingleChildScrollView(
          physics: AlwaysScrollableScrollPhysics(),
          child: Column(
            children: [
              teamInfoWidget(),
              SizedBox(
                height: ScreenHelper.height(20),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 个人信息
  Widget teamInfoWidget() {
    return SizedBox(
      child: GetBuilder<PersonalController>(
        id: 'personalInfo',
        builder: (controller) => ListView.separated(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              Map item = controller.basicInfoList[index];
              if (index == 0) {
                return GestureDetector(
                  onTap: () {
                    controller.showSelectImg();
                  },
                  child: buildBaseInfoItem(
                    attrName: item['attr'],
                    value: controller.headImgUrl.value,
                    isHead: true,
                  ),
                );
              }
              if (index == 1) {
                return buildUpdateInfoItem(
                    attrName: item['attr'],
                    value: item['value'],
                    isHead: false,
                    inputController: controller.nickInputController,
                    focusNode: controller.namefocusNode,
                    onSubmitted: (value) {
                      controller.namefocusNode.unfocus();
                    },
                    onEditingComplete: () {
                      FocusScope.of(context)
                          .requestFocus(controller.namefocusNode);
                      controller.updateDrInfo();
                    },
                    isEnalbe: item['isEdit']);
              }
              if (index == 2) {
                return buildBaseInfoItem(
                    attrName: item['attr'],
                    value: controller.doctorNo.value,
                    isHead: false,
                    isEnable: false);
              }

              if (index == 3) {
                return buildBaseInfoItem(
                    attrName: item['attr'],
                    value: controller.phone.value,
                    isHead: false,
                    isEnable: false);
              }
              if (index == 4) {
                return GetBuilder<PersonalController>(
                  id: 'personalInfo',
                  builder: (controller) => GestureDetector(
                    onTap: () async {
                      await controller.getDutyList(type: "doctor_duty");
                      if (controller.dutyList.isEmpty) {
                        ToastUtils.toast("列表为空");
                        return;
                      }
                      BottomSheetTool.singlePickerView(
                          dataList: controller.dutyList.value,
                          selectData: controller.selectDuty.value,
                          onConfirm: (res, int) {
                            controller.selectDuty.value = res;
                            controller.selectDutyId.value = controller
                                .allDutyList[int].dictValue
                                .toString();
                          });
                    },
                    child: Obx(() => buildBaseInfoItem(
                        attrName: item['attr'],
                        value: controller.selectDuty.value,
                        isHead: false,
                        isArrow: true)),
                  ),
                );
              }
              if (index == 5) {
                return GetBuilder<PersonalController>(
                  id: 'personalInfo',
                  builder: (controller) => inputAreaBox(
                      hint: '',
                      title: '个人简介',
                      countNum: '',
                      textControlller: controller.profileController),
                );
              }
              if (index == 6) {
                return GetBuilder<PersonalController>(
                  id: 'personalInfo',
                  builder: (controller) => inputAreaBox(
                      hint: '',
                      title: '擅长领域',
                      countNum: '',
                      textControlller: controller.goodController),
                );
              }
            },
            separatorBuilder: (context, index) => divider(),
            itemCount: controller.basicInfoList.length),
      ),
    );
  }
}
